package com.jkgh.remedium.rsgen.generator.java;

import java.io.File;
import java.io.FileNotFoundException;

import com.jkgh.remedium.rsgen.vo.DataObject;
import com.jkgh.remedium.rsgen.vo.MethodObject;
import com.jkgh.remedium.rsgen.vo.RemediumSystem;

public class RemediumSystemJavaGenerator {

	public static void generate(File outputDir, RemediumSystem rs) throws FileNotFoundException {

		String packagePath = rs.getPackageName().replace('.', '/');
		outputDir = new File(outputDir, packagePath);
		outputDir.mkdirs();

		deleteContents(outputDir);

		for (DataObject d : rs.getDataObjects()) {
			RemediumDataObjectJavaGenerator.generate(outputDir, d, rs.getPackageName());
		}

		for (MethodObject m : rs.getMethodObjects()) {
			RemediumMethodObjectJavaGenerator.generate(outputDir, m, rs.getPackageName());
		}
	}

	private static void deleteContents(File dir) {

		for (File f : dir.listFiles()) {
			if (f.isDirectory()) {
				deleteContents(f);
			}
			f.delete();
		}
	}
}
